﻿CREATE PROCEDURE [acms].[Post_GetAllByMenuIdAndParentGuid]
	@MenuId int, 
	@ParentGuid uniqueidentifier,
	@SiteVersion DateTime
AS
	--Version 2 checked
	declare @tmp datetime
	if(@SiteVersion is not null)
		set @tmp = acms.GetPublishDate(@SiteVersion)
	if(@tmp is null and @SiteVersion is not null)
		return
		
	SELECT a.*, b.ParentPath, b.PublishDate as SiteVersion
	FROM [Post_View] a
		inner join acms.PostPositions b on a.Id = b.PostId and (b.PublishDate = @tmp or (b.PublishDate is null and @tmp is null))
	Where a.ParentGuid = @ParentGuid
		and a.Id in (Select PostId from [PostMenu] where MenuId = @MenuId and Included = 1)
	ORDER By Sequence
RETURN 0;RETURN 0;